package com.pengweiwei.androidzygote.main;


import android.content.Context;

import com.putong35.common.app.BaseApplication;
import com.putong35.common.secretcode.SecretCodeActivity;
import com.pengweiwei.androidzygote.BuildConfig;
import com.pengweiwei.androidzygote.message.dao.DaoMaster;
import com.pengweiwei.androidzygote.message.dao.DaoSession;

/**
 * Warning: 注意这里的BuildConfig配置类。
 */
public class MyApplication extends BaseApplication {

    @Override
    public void onCreate() {
        super.onCreate();
        SecretCodeActivity.setBuildType(BuildConfig.BUILD_TYPE);
    }


    private static DaoMaster mDaoMaster;
    private static DaoSession mDaoSession;

    // 注意这里的BuildConfig配置类。
    public static final String DATABASE_NAME = com.putong35.common.BuildConfig.PROJECT_NAME + ".db";

    public static DaoMaster getDaoMaster(Context context) {
        if (mDaoMaster == null) {
            DaoMaster.OpenHelper helper = new DaoMaster.DevOpenHelper(context, DATABASE_NAME, null);
            mDaoMaster = new DaoMaster(helper.getWritableDatabase());
        }
        return mDaoMaster;
    }


/**
     * 取得DaoSession
     *
     * @param context
     * @return
     */

    public static DaoSession getDaoSession(Context context) {
        if (mDaoSession == null) {
            if (mDaoMaster == null) {
                mDaoMaster = getDaoMaster(context);
            }
            mDaoSession = mDaoMaster.newSession();
        }
        return mDaoSession;
    }


}
